{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 前言\n",
    "###  Pandas库提供了专门从财经网站获取金融数据的API接口，可作为量化交易股票数据获取的另一种途径，该接口在urllib3库基础上实现了以客户端身份访问网站的股票数据。需要注意的是目前模块已经迁徙到pandas-datareader包中，因此导入模块时需要由import pandas.io.data as web更改为import pandas_datareader.data as web。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DataReader方法介绍\n",
    "### 查看Pandas的手册可以发现，第一个参数为股票代码，苹果公司的代码为\"AAPL\"，国内股市采用的输入方式“股票代码”+“对应股市”，上证股票在股票代码后面加上“.SS”，深圳股票在股票代码后面加上“.SZ”。DataReader可从多个金融网站获取到股票数据，如“Yahoo! Finance” 、“Google Finance”等，这里以Yahoo为例。第三、四个参数为股票数据的起始时间断。返回的数据格式为DataFrame。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 基本信息\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series, DataFrame\n",
    "\n",
    "# 股票数据的读取\n",
    "import pandas_datareader as pdr\n",
    "\n",
    "# 可视化\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "%matplotlib inline\n",
    "\n",
    "# time\n",
    "import datetime\n",
    "\n",
    "start = datetime.datetime(2017,1,1)#获取数据的时间段-起始时间\n",
    "end = datetime.date.today()#获取数据的时间段-结束时间\n",
    "stock = pdr.DataReader(\"600519.SS\", \"yahoo\", start, end)#获取贵州茅台 2017年1月1日至今的股票数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据分析\n",
    "### 1、打印DataFrame数据前5行和尾部倒数5行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Adj Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>337.000000</td>\n",
       "      <td>332.809998</td>\n",
       "      <td>334.279999</td>\n",
       "      <td>334.559998</td>\n",
       "      <td>2076389.0</td>\n",
       "      <td>324.968994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>352.170013</td>\n",
       "      <td>334.600006</td>\n",
       "      <td>334.619995</td>\n",
       "      <td>351.910004</td>\n",
       "      <td>6525738.0</td>\n",
       "      <td>341.821655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>351.450012</td>\n",
       "      <td>345.440002</td>\n",
       "      <td>350.000000</td>\n",
       "      <td>346.739990</td>\n",
       "      <td>4170448.0</td>\n",
       "      <td>336.799835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>359.779999</td>\n",
       "      <td>346.100006</td>\n",
       "      <td>346.640015</td>\n",
       "      <td>350.760010</td>\n",
       "      <td>6809562.0</td>\n",
       "      <td>340.704620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>352.880005</td>\n",
       "      <td>346.540009</td>\n",
       "      <td>347.799988</td>\n",
       "      <td>348.510010</td>\n",
       "      <td>3540500.0</td>\n",
       "      <td>338.519135</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  High         Low        Open       Close     Volume  \\\n",
       "Date                                                                    \n",
       "2017-01-03  337.000000  332.809998  334.279999  334.559998  2076389.0   \n",
       "2017-01-04  352.170013  334.600006  334.619995  351.910004  6525738.0   \n",
       "2017-01-05  351.450012  345.440002  350.000000  346.739990  4170448.0   \n",
       "2017-01-06  359.779999  346.100006  346.640015  350.760010  6809562.0   \n",
       "2017-01-09  352.880005  346.540009  347.799988  348.510010  3540500.0   \n",
       "\n",
       "             Adj Close  \n",
       "Date                    \n",
       "2017-01-03  324.968994  \n",
       "2017-01-04  341.821655  \n",
       "2017-01-05  336.799835  \n",
       "2017-01-06  340.704620  \n",
       "2017-01-09  338.519135  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Adj Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>607.669983</td>\n",
       "      <td>582.020020</td>\n",
       "      <td>587.280029</td>\n",
       "      <td>602.000000</td>\n",
       "      <td>3768347.0</td>\n",
       "      <td>602.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>610.299988</td>\n",
       "      <td>602.219971</td>\n",
       "      <td>587.280029</td>\n",
       "      <td>605.489990</td>\n",
       "      <td>3475013.0</td>\n",
       "      <td>605.489990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>612.000000</td>\n",
       "      <td>600.280029</td>\n",
       "      <td>605.500000</td>\n",
       "      <td>604.789978</td>\n",
       "      <td>2883813.0</td>\n",
       "      <td>604.789978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>626.159973</td>\n",
       "      <td>609.039978</td>\n",
       "      <td>609.989990</td>\n",
       "      <td>616.119995</td>\n",
       "      <td>4989227.0</td>\n",
       "      <td>616.119995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>624.880005</td>\n",
       "      <td>610.250000</td>\n",
       "      <td>617.130005</td>\n",
       "      <td>618.750000</td>\n",
       "      <td>2880790.0</td>\n",
       "      <td>618.750000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  High         Low        Open       Close     Volume  \\\n",
       "Date                                                                    \n",
       "2019-01-04  607.669983  582.020020  587.280029  602.000000  3768347.0   \n",
       "2019-01-07  610.299988  602.219971  587.280029  605.489990  3475013.0   \n",
       "2019-01-08  612.000000  600.280029  605.500000  604.789978  2883813.0   \n",
       "2019-01-09  626.159973  609.039978  609.989990  616.119995  4989227.0   \n",
       "2019-01-10  624.880005  610.250000  617.130005  618.750000  2880790.0   \n",
       "\n",
       "             Adj Close  \n",
       "Date                    \n",
       "2019-01-04  602.000000  \n",
       "2019-01-07  605.489990  \n",
       "2019-01-08  604.789978  \n",
       "2019-01-09  616.119995  \n",
       "2019-01-10  618.750000  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2、打印DataFrame数据索引和列名，索引为时间序列，列信息为开盘价、最高价、最低价、收盘价、复权收盘价、成交量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2017-01-03', '2017-01-04', '2017-01-05', '2017-01-06',\n",
       "               '2017-01-09', '2017-01-10', '2017-01-11', '2017-01-12',\n",
       "               '2017-01-13', '2017-01-16',\n",
       "               ...\n",
       "               '2018-12-27', '2018-12-28', '2018-12-31', '2019-01-02',\n",
       "               '2019-01-03', '2019-01-04', '2019-01-07', '2019-01-08',\n",
       "               '2019-01-09', '2019-01-10'],\n",
       "              dtype='datetime64[ns]', name='Date', length=495, freq=None)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['High', 'Low', 'Open', 'Close', 'Volume', 'Adj Close'], dtype='object')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3、打印DataFrame数据形状，index长度为248，columns数为6，即248个交易日，6项股票数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(495, 6)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4、打印DataFrame数据查看数据是否有缺失，以及每列数据的类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "DatetimeIndex: 495 entries, 2017-01-03 to 2019-01-10\n",
      "Data columns (total 6 columns):\n",
      "High         495 non-null float64\n",
      "Low          495 non-null float64\n",
      "Open         495 non-null float64\n",
      "Close        495 non-null float64\n",
      "Volume       495 non-null float64\n",
      "Adj Close    495 non-null float64\n",
      "dtypes: float64(6)\n",
      "memory usage: 27.1 KB\n"
     ]
    }
   ],
   "source": [
    "stock.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5、打印DataFrame数据每组的统计情况，如最小值、最大值、均值、标准差等"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Adj Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>495.000000</td>\n",
       "      <td>495.000000</td>\n",
       "      <td>495.000000</td>\n",
       "      <td>495.000000</td>\n",
       "      <td>4.950000e+02</td>\n",
       "      <td>495.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>589.368303</td>\n",
       "      <td>574.696264</td>\n",
       "      <td>581.641575</td>\n",
       "      <td>582.365030</td>\n",
       "      <td>4.086742e+06</td>\n",
       "      <td>575.367626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>137.211361</td>\n",
       "      <td>131.962093</td>\n",
       "      <td>135.002633</td>\n",
       "      <td>134.529965</td>\n",
       "      <td>2.086036e+06</td>\n",
       "      <td>136.084147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>337.000000</td>\n",
       "      <td>332.809998</td>\n",
       "      <td>334.279999</td>\n",
       "      <td>334.559998</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>324.968994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>474.880005</td>\n",
       "      <td>465.845001</td>\n",
       "      <td>471.300003</td>\n",
       "      <td>472.279999</td>\n",
       "      <td>2.739534e+06</td>\n",
       "      <td>459.187759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>613.000000</td>\n",
       "      <td>600.280029</td>\n",
       "      <td>605.500000</td>\n",
       "      <td>610.099976</td>\n",
       "      <td>3.632653e+06</td>\n",
       "      <td>608.061707</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>708.750000</td>\n",
       "      <td>685.955017</td>\n",
       "      <td>697.645020</td>\n",
       "      <td>697.250000</td>\n",
       "      <td>4.827626e+06</td>\n",
       "      <td>692.004425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>803.500000</td>\n",
       "      <td>788.880005</td>\n",
       "      <td>800.000000</td>\n",
       "      <td>799.190002</td>\n",
       "      <td>2.043967e+07</td>\n",
       "      <td>788.008301</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             High         Low        Open       Close        Volume  \\\n",
       "count  495.000000  495.000000  495.000000  495.000000  4.950000e+02   \n",
       "mean   589.368303  574.696264  581.641575  582.365030  4.086742e+06   \n",
       "std    137.211361  131.962093  135.002633  134.529965  2.086036e+06   \n",
       "min    337.000000  332.809998  334.279999  334.559998  0.000000e+00   \n",
       "25%    474.880005  465.845001  471.300003  472.279999  2.739534e+06   \n",
       "50%    613.000000  600.280029  605.500000  610.099976  3.632653e+06   \n",
       "75%    708.750000  685.955017  697.645020  697.250000  4.827626e+06   \n",
       "max    803.500000  788.880005  800.000000  799.190002  2.043967e+07   \n",
       "\n",
       "        Adj Close  \n",
       "count  495.000000  \n",
       "mean   575.367626  \n",
       "std    136.084147  \n",
       "min    324.968994  \n",
       "25%    459.187759  \n",
       "50%    608.061707  \n",
       "75%    692.004425  \n",
       "max    788.008301  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6、DataFrame数据中增加涨/跌幅列，涨/跌=（当日Close-上一日Close）/上一日Close*100%\n",
    "#### （1）添加一列change，存储当日股票价格与前一日收盘价格相比的涨跌数值，即当日Close价格与上一日Close的差值，1月3日这天无上一日数据，因此出现缺失"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Change</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>337.000000</td>\n",
       "      <td>332.809998</td>\n",
       "      <td>334.279999</td>\n",
       "      <td>334.559998</td>\n",
       "      <td>2076389.0</td>\n",
       "      <td>324.968994</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>352.170013</td>\n",
       "      <td>334.600006</td>\n",
       "      <td>334.619995</td>\n",
       "      <td>351.910004</td>\n",
       "      <td>6525738.0</td>\n",
       "      <td>341.821655</td>\n",
       "      <td>17.350006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>351.450012</td>\n",
       "      <td>345.440002</td>\n",
       "      <td>350.000000</td>\n",
       "      <td>346.739990</td>\n",
       "      <td>4170448.0</td>\n",
       "      <td>336.799835</td>\n",
       "      <td>-5.170013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>359.779999</td>\n",
       "      <td>346.100006</td>\n",
       "      <td>346.640015</td>\n",
       "      <td>350.760010</td>\n",
       "      <td>6809562.0</td>\n",
       "      <td>340.704620</td>\n",
       "      <td>4.020020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>352.880005</td>\n",
       "      <td>346.540009</td>\n",
       "      <td>347.799988</td>\n",
       "      <td>348.510010</td>\n",
       "      <td>3540500.0</td>\n",
       "      <td>338.519135</td>\n",
       "      <td>-2.250000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  High         Low        Open       Close     Volume  \\\n",
       "Date                                                                    \n",
       "2017-01-03  337.000000  332.809998  334.279999  334.559998  2076389.0   \n",
       "2017-01-04  352.170013  334.600006  334.619995  351.910004  6525738.0   \n",
       "2017-01-05  351.450012  345.440002  350.000000  346.739990  4170448.0   \n",
       "2017-01-06  359.779999  346.100006  346.640015  350.760010  6809562.0   \n",
       "2017-01-09  352.880005  346.540009  347.799988  348.510010  3540500.0   \n",
       "\n",
       "             Adj Close     Change  \n",
       "Date                               \n",
       "2017-01-03  324.968994        NaN  \n",
       "2017-01-04  341.821655  17.350006  \n",
       "2017-01-05  336.799835  -5.170013  \n",
       "2017-01-06  340.704620   4.020020  \n",
       "2017-01-09  338.519135  -2.250000  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "change = stock.Close.diff()\n",
    "stock['Change'] = change\n",
    "stock.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### （2）对缺失的数据用涨跌值的均值就地替代NaN。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "change.fillna(change.mean(),inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### （3）计算涨跌幅度有两种方法，pct_change()算法的思想即是第二项开始向前做减法后再除以第一项，计算得到涨跌幅序列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock['pct_change'] = (stock['Change'] /stock['Close'].shift(1))#\n",
    "stock['pct_change1'] = stock.Close.pct_change()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7、DataFrame数据中增加跳空缺口数值序列，这里定义的缺口为上涨趋势和下跌趋势中的突破缺口，上涨趋势中今天的最低价高于昨天收盘价为向上跳空，下跌趋势中昨天收盘价高于今天最高价为向下跳空。遍历每个交易日后将符合跳空缺口条件的交易日增加缺口数值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\program files\\python36\\lib\\site-packages\\ipykernel_launcher.py:3: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n",
      "c:\\program files\\python36\\lib\\site-packages\\ipykernel_launcher.py:4: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  after removing the cwd from sys.path.\n",
      "c:\\program files\\python36\\lib\\site-packages\\ipykernel_launcher.py:5: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \"\"\"\n",
      "c:\\program files\\python36\\lib\\site-packages\\pandas\\core\\series.py:914: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  self.loc[key] = value\n",
      "c:\\program files\\python36\\lib\\site-packages\\ipykernel_launcher.py:7: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  import sys\n",
      "c:\\program files\\python36\\lib\\site-packages\\ipykernel_launcher.py:9: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  if __name__ == '__main__':\n"
     ]
    }
   ],
   "source": [
    "jump_pd = pd.DataFrame()\n",
    "for kl_index in np.arange(1, stock.shape[0]):\n",
    "    today = stock.ix[kl_index]\n",
    "    yesday = stock.ix[kl_index-1]\n",
    "    today['preCloae'] = yesday.Close   \n",
    "    if today['pct_change'] > 0 and (today.Low-today['preCloae']) > 0:\n",
    "        today['jump_power'] = (today.Low-today['preCloae'])\n",
    "    elif  today['pct_change'] < 0 and (today.High-today['preCloae']) < 0:\n",
    "        today['jump_power'] = (today.High-today['preCloae'])\n",
    "    jump_pd = jump_pd.append(today)        \n",
    "    stock['jump_power'] = jump_pd['jump_power']\n",
    "    stock.loc[\"2017-04-26\":\"2017-06-15\"]#默认打印全部列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8、DataFrame数据保留两位小数显示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Change</th>\n",
       "      <th>pct_change</th>\n",
       "      <th>pct_change1</th>\n",
       "      <th>jump_power</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-04-26</th>\n",
       "      <td>428.68</td>\n",
       "      <td>413.01</td>\n",
       "      <td>418.85</td>\n",
       "      <td>417.96</td>\n",
       "      <td>5662412.00</td>\n",
       "      <td>405.98</td>\n",
       "      <td>-0.93</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-04-27</th>\n",
       "      <td>421.97</td>\n",
       "      <td>410.43</td>\n",
       "      <td>415.53</td>\n",
       "      <td>421.44</td>\n",
       "      <td>2824071.00</td>\n",
       "      <td>409.36</td>\n",
       "      <td>3.48</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-04-28</th>\n",
       "      <td>423.00</td>\n",
       "      <td>409.90</td>\n",
       "      <td>421.99</td>\n",
       "      <td>413.48</td>\n",
       "      <td>4950587.00</td>\n",
       "      <td>401.63</td>\n",
       "      <td>-7.96</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-02</th>\n",
       "      <td>415.00</td>\n",
       "      <td>409.18</td>\n",
       "      <td>411.60</td>\n",
       "      <td>412.08</td>\n",
       "      <td>2329168.00</td>\n",
       "      <td>400.27</td>\n",
       "      <td>-1.40</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-03</th>\n",
       "      <td>417.66</td>\n",
       "      <td>411.00</td>\n",
       "      <td>411.00</td>\n",
       "      <td>417.61</td>\n",
       "      <td>2026791.00</td>\n",
       "      <td>405.64</td>\n",
       "      <td>5.53</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-04</th>\n",
       "      <td>418.48</td>\n",
       "      <td>414.63</td>\n",
       "      <td>414.63</td>\n",
       "      <td>416.00</td>\n",
       "      <td>2670915.00</td>\n",
       "      <td>404.07</td>\n",
       "      <td>-1.61</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-05</th>\n",
       "      <td>422.78</td>\n",
       "      <td>415.10</td>\n",
       "      <td>416.20</td>\n",
       "      <td>416.19</td>\n",
       "      <td>3743711.00</td>\n",
       "      <td>404.26</td>\n",
       "      <td>0.19</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-08</th>\n",
       "      <td>417.00</td>\n",
       "      <td>404.72</td>\n",
       "      <td>416.18</td>\n",
       "      <td>405.48</td>\n",
       "      <td>4072165.00</td>\n",
       "      <td>393.86</td>\n",
       "      <td>-10.71</td>\n",
       "      <td>-0.03</td>\n",
       "      <td>-0.03</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-09</th>\n",
       "      <td>409.88</td>\n",
       "      <td>398.00</td>\n",
       "      <td>404.44</td>\n",
       "      <td>408.76</td>\n",
       "      <td>5280192.00</td>\n",
       "      <td>397.04</td>\n",
       "      <td>3.28</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-10</th>\n",
       "      <td>414.44</td>\n",
       "      <td>407.02</td>\n",
       "      <td>408.40</td>\n",
       "      <td>410.09</td>\n",
       "      <td>2603938.00</td>\n",
       "      <td>398.33</td>\n",
       "      <td>1.33</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-11</th>\n",
       "      <td>414.70</td>\n",
       "      <td>406.51</td>\n",
       "      <td>408.40</td>\n",
       "      <td>412.16</td>\n",
       "      <td>3046764.00</td>\n",
       "      <td>400.34</td>\n",
       "      <td>2.07</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-12</th>\n",
       "      <td>415.30</td>\n",
       "      <td>410.01</td>\n",
       "      <td>413.59</td>\n",
       "      <td>413.47</td>\n",
       "      <td>2233742.00</td>\n",
       "      <td>401.62</td>\n",
       "      <td>1.31</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-15</th>\n",
       "      <td>420.35</td>\n",
       "      <td>413.12</td>\n",
       "      <td>413.12</td>\n",
       "      <td>419.55</td>\n",
       "      <td>3344735.00</td>\n",
       "      <td>407.52</td>\n",
       "      <td>6.08</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-16</th>\n",
       "      <td>431.22</td>\n",
       "      <td>418.26</td>\n",
       "      <td>419.60</td>\n",
       "      <td>430.12</td>\n",
       "      <td>5016490.00</td>\n",
       "      <td>417.79</td>\n",
       "      <td>10.57</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.03</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-17</th>\n",
       "      <td>430.19</td>\n",
       "      <td>424.88</td>\n",
       "      <td>429.00</td>\n",
       "      <td>426.60</td>\n",
       "      <td>2751521.00</td>\n",
       "      <td>414.37</td>\n",
       "      <td>-3.52</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-18</th>\n",
       "      <td>430.70</td>\n",
       "      <td>425.01</td>\n",
       "      <td>425.05</td>\n",
       "      <td>429.54</td>\n",
       "      <td>2430080.00</td>\n",
       "      <td>417.23</td>\n",
       "      <td>2.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-19</th>\n",
       "      <td>441.80</td>\n",
       "      <td>429.57</td>\n",
       "      <td>429.57</td>\n",
       "      <td>440.82</td>\n",
       "      <td>3831083.00</td>\n",
       "      <td>428.18</td>\n",
       "      <td>11.28</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-22</th>\n",
       "      <td>446.01</td>\n",
       "      <td>436.20</td>\n",
       "      <td>439.04</td>\n",
       "      <td>441.78</td>\n",
       "      <td>3532149.00</td>\n",
       "      <td>429.12</td>\n",
       "      <td>0.96</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-23</th>\n",
       "      <td>454.47</td>\n",
       "      <td>442.25</td>\n",
       "      <td>442.25</td>\n",
       "      <td>454.20</td>\n",
       "      <td>4845439.00</td>\n",
       "      <td>441.18</td>\n",
       "      <td>12.42</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-24</th>\n",
       "      <td>456.48</td>\n",
       "      <td>446.00</td>\n",
       "      <td>452.90</td>\n",
       "      <td>450.32</td>\n",
       "      <td>4022618.00</td>\n",
       "      <td>437.41</td>\n",
       "      <td>-3.88</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-25</th>\n",
       "      <td>452.96</td>\n",
       "      <td>447.50</td>\n",
       "      <td>448.71</td>\n",
       "      <td>450.60</td>\n",
       "      <td>2889842.00</td>\n",
       "      <td>437.68</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-26</th>\n",
       "      <td>455.60</td>\n",
       "      <td>448.00</td>\n",
       "      <td>450.82</td>\n",
       "      <td>451.92</td>\n",
       "      <td>2738664.00</td>\n",
       "      <td>438.96</td>\n",
       "      <td>1.32</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-05-31</th>\n",
       "      <td>450.50</td>\n",
       "      <td>440.11</td>\n",
       "      <td>450.00</td>\n",
       "      <td>442.94</td>\n",
       "      <td>4431225.00</td>\n",
       "      <td>430.24</td>\n",
       "      <td>-8.98</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-1.42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-01</th>\n",
       "      <td>449.95</td>\n",
       "      <td>441.01</td>\n",
       "      <td>442.50</td>\n",
       "      <td>449.28</td>\n",
       "      <td>4060478.00</td>\n",
       "      <td>436.40</td>\n",
       "      <td>6.34</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-02</th>\n",
       "      <td>450.95</td>\n",
       "      <td>445.60</td>\n",
       "      <td>450.00</td>\n",
       "      <td>447.31</td>\n",
       "      <td>2178526.00</td>\n",
       "      <td>434.49</td>\n",
       "      <td>-1.97</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-05</th>\n",
       "      <td>449.00</td>\n",
       "      <td>442.35</td>\n",
       "      <td>448.04</td>\n",
       "      <td>444.41</td>\n",
       "      <td>1924120.00</td>\n",
       "      <td>431.67</td>\n",
       "      <td>-2.90</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-06</th>\n",
       "      <td>449.00</td>\n",
       "      <td>444.20</td>\n",
       "      <td>444.97</td>\n",
       "      <td>448.82</td>\n",
       "      <td>2040244.00</td>\n",
       "      <td>435.95</td>\n",
       "      <td>4.41</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-07</th>\n",
       "      <td>460.00</td>\n",
       "      <td>449.12</td>\n",
       "      <td>449.12</td>\n",
       "      <td>459.37</td>\n",
       "      <td>3883430.00</td>\n",
       "      <td>446.20</td>\n",
       "      <td>10.55</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-08</th>\n",
       "      <td>464.40</td>\n",
       "      <td>458.50</td>\n",
       "      <td>461.32</td>\n",
       "      <td>464.31</td>\n",
       "      <td>2895111.00</td>\n",
       "      <td>451.00</td>\n",
       "      <td>4.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-09</th>\n",
       "      <td>470.80</td>\n",
       "      <td>463.00</td>\n",
       "      <td>464.24</td>\n",
       "      <td>465.74</td>\n",
       "      <td>3143076.00</td>\n",
       "      <td>452.39</td>\n",
       "      <td>1.43</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-12</th>\n",
       "      <td>475.44</td>\n",
       "      <td>465.00</td>\n",
       "      <td>467.00</td>\n",
       "      <td>472.88</td>\n",
       "      <td>3510916.00</td>\n",
       "      <td>459.32</td>\n",
       "      <td>7.14</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.02</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-13</th>\n",
       "      <td>474.50</td>\n",
       "      <td>467.00</td>\n",
       "      <td>473.05</td>\n",
       "      <td>473.04</td>\n",
       "      <td>2423798.00</td>\n",
       "      <td>459.48</td>\n",
       "      <td>0.16</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-14</th>\n",
       "      <td>477.50</td>\n",
       "      <td>470.48</td>\n",
       "      <td>472.79</td>\n",
       "      <td>474.39</td>\n",
       "      <td>3376863.00</td>\n",
       "      <td>460.79</td>\n",
       "      <td>1.35</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-06-15</th>\n",
       "      <td>475.48</td>\n",
       "      <td>464.00</td>\n",
       "      <td>475.00</td>\n",
       "      <td>464.30</td>\n",
       "      <td>5020280.00</td>\n",
       "      <td>450.99</td>\n",
       "      <td>-10.09</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              High     Low    Open   Close      Volume Adj Close  Change  \\\n",
       "Date                                                                       \n",
       "2017-04-26  428.68  413.01  418.85  417.96  5662412.00    405.98   -0.93   \n",
       "2017-04-27  421.97  410.43  415.53  421.44  2824071.00    409.36    3.48   \n",
       "2017-04-28  423.00  409.90  421.99  413.48  4950587.00    401.63   -7.96   \n",
       "2017-05-02  415.00  409.18  411.60  412.08  2329168.00    400.27   -1.40   \n",
       "2017-05-03  417.66  411.00  411.00  417.61  2026791.00    405.64    5.53   \n",
       "2017-05-04  418.48  414.63  414.63  416.00  2670915.00    404.07   -1.61   \n",
       "2017-05-05  422.78  415.10  416.20  416.19  3743711.00    404.26    0.19   \n",
       "2017-05-08  417.00  404.72  416.18  405.48  4072165.00    393.86  -10.71   \n",
       "2017-05-09  409.88  398.00  404.44  408.76  5280192.00    397.04    3.28   \n",
       "2017-05-10  414.44  407.02  408.40  410.09  2603938.00    398.33    1.33   \n",
       "2017-05-11  414.70  406.51  408.40  412.16  3046764.00    400.34    2.07   \n",
       "2017-05-12  415.30  410.01  413.59  413.47  2233742.00    401.62    1.31   \n",
       "2017-05-15  420.35  413.12  413.12  419.55  3344735.00    407.52    6.08   \n",
       "2017-05-16  431.22  418.26  419.60  430.12  5016490.00    417.79   10.57   \n",
       "2017-05-17  430.19  424.88  429.00  426.60  2751521.00    414.37   -3.52   \n",
       "2017-05-18  430.70  425.01  425.05  429.54  2430080.00    417.23    2.94   \n",
       "2017-05-19  441.80  429.57  429.57  440.82  3831083.00    428.18   11.28   \n",
       "2017-05-22  446.01  436.20  439.04  441.78  3532149.00    429.12    0.96   \n",
       "2017-05-23  454.47  442.25  442.25  454.20  4845439.00    441.18   12.42   \n",
       "2017-05-24  456.48  446.00  452.90  450.32  4022618.00    437.41   -3.88   \n",
       "2017-05-25  452.96  447.50  448.71  450.60  2889842.00    437.68    0.28   \n",
       "2017-05-26  455.60  448.00  450.82  451.92  2738664.00    438.96    1.32   \n",
       "2017-05-31  450.50  440.11  450.00  442.94  4431225.00    430.24   -8.98   \n",
       "2017-06-01  449.95  441.01  442.50  449.28  4060478.00    436.40    6.34   \n",
       "2017-06-02  450.95  445.60  450.00  447.31  2178526.00    434.49   -1.97   \n",
       "2017-06-05  449.00  442.35  448.04  444.41  1924120.00    431.67   -2.90   \n",
       "2017-06-06  449.00  444.20  444.97  448.82  2040244.00    435.95    4.41   \n",
       "2017-06-07  460.00  449.12  449.12  459.37  3883430.00    446.20   10.55   \n",
       "2017-06-08  464.40  458.50  461.32  464.31  2895111.00    451.00    4.94   \n",
       "2017-06-09  470.80  463.00  464.24  465.74  3143076.00    452.39    1.43   \n",
       "2017-06-12  475.44  465.00  467.00  472.88  3510916.00    459.32    7.14   \n",
       "2017-06-13  474.50  467.00  473.05  473.04  2423798.00    459.48    0.16   \n",
       "2017-06-14  477.50  470.48  472.79  474.39  3376863.00    460.79    1.35   \n",
       "2017-06-15  475.48  464.00  475.00  464.30  5020280.00    450.99  -10.09   \n",
       "\n",
       "           pct_change pct_change1 jump_power  \n",
       "Date                                          \n",
       "2017-04-26      -0.00       -0.00        nan  \n",
       "2017-04-27       0.01        0.01        nan  \n",
       "2017-04-28      -0.02       -0.02        nan  \n",
       "2017-05-02      -0.00       -0.00        nan  \n",
       "2017-05-03       0.01        0.01        nan  \n",
       "2017-05-04      -0.00       -0.00        nan  \n",
       "2017-05-05       0.00        0.00        nan  \n",
       "2017-05-08      -0.03       -0.03        nan  \n",
       "2017-05-09       0.01        0.01        nan  \n",
       "2017-05-10       0.00        0.00        nan  \n",
       "2017-05-11       0.01        0.01        nan  \n",
       "2017-05-12       0.00        0.00        nan  \n",
       "2017-05-15       0.01        0.01        nan  \n",
       "2017-05-16       0.03        0.03        nan  \n",
       "2017-05-17      -0.01       -0.01        nan  \n",
       "2017-05-18       0.01        0.01        nan  \n",
       "2017-05-19       0.03        0.03       0.03  \n",
       "2017-05-22       0.00        0.00        nan  \n",
       "2017-05-23       0.03        0.03       0.47  \n",
       "2017-05-24      -0.01       -0.01        nan  \n",
       "2017-05-25       0.00        0.00        nan  \n",
       "2017-05-26       0.00        0.00        nan  \n",
       "2017-05-31      -0.02       -0.02      -1.42  \n",
       "2017-06-01       0.01        0.01        nan  \n",
       "2017-06-02      -0.00       -0.00        nan  \n",
       "2017-06-05      -0.01       -0.01        nan  \n",
       "2017-06-06       0.01        0.01        nan  \n",
       "2017-06-07       0.02        0.02       0.30  \n",
       "2017-06-08       0.01        0.01        nan  \n",
       "2017-06-09       0.00        0.00        nan  \n",
       "2017-06-12       0.02        0.02        nan  \n",
       "2017-06-13       0.00        0.00        nan  \n",
       "2017-06-14       0.00        0.00        nan  \n",
       "2017-06-15      -0.02       -0.02        nan  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "format = lambda x: '%.2f' % x\n",
    "stock = stock.applymap(format)\n",
    "stock.loc[\"2017-04-26\":\"2017-06-15\"]#默认打印全部列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
